<template>
	<div class="lietou-list content">
		<div class="lietou-right">
			<el-form ref="form" :inline="true" label-width="90px" size="small">
				<el-form-item label="手机号" label-width="80px">
					<el-input placeholder="请输入手机号" v-model="searchPhone" maxlength="11" clearable class="search-input"></el-input>
				</el-form-item>
				<el-form-item label="名称">
					<el-input placeholder="请输入名称" v-model="nickname" class="search-input" clearable></el-input>
				</el-form-item>
				<el-form-item style="margin:-2px 0 0 10px;">
					<el-button icon="el-icon-search" @click="searchData" class="buttonStyle">搜索</el-button>
				</el-form-item>
			</el-form>
			<el-table header-row-class-name="my-table-header" :data="tableData" class="answerTable" style="width: 100%;"
			 :header-cell-style="{ background: '#eee',color:'#555555'}" stripe :row-style="{height:'54px'}"
			 :highlight-current-row="true">
				<el-table-column fixed type="index" label="序列" width="80" column-key="id" align="center"></el-table-column>
				<el-table-column prop="id" label="ID" width="120" align="center"></el-table-column>
				<el-table-column prop="new_c_name" label="公司名称" align="center"></el-table-column>
				<el-table-column prop="usertel" label="手机号码" align="center"></el-table-column>
				<el-table-column prop="new_title" label="注册人职位" align="center"></el-table-column>
				<el-table-column prop="new_time" label="提交日期" align="center"></el-table-column>
			
				<el-table-column align="center" label="操作" width="150">
					<template slot-scope="scope">
						<router-link :to="{path:'/companyDetail',query:{id:scope.row.id}}">
							<el-button type="primary" icon="el-icon-edit" size="small" class="buttonStyle">详情</el-button>
						</router-link>
					</template>
				</el-table-column>
			</el-table>
			<el-row type="flex" class="row-bg" justify="center" v-show="pageCount>1">
				<el-col :span="24" style="text-align:center;margin-top:50px">
					<el-pagination background layout="prev, pager, next" :page-size="pageSize" :page-count="pageCount" :current-page="pageNo"
					 @current-change="pageChange">
					</el-pagination>
				</el-col>
			</el-row>
		</div>
	</div>
</template>

<script>
	import { mapGetters } from 'vuex'
	export default {
		name: 'CompanyList',
		computed: {
			...mapGetters([
				'token'
			])
		},
		data() {
			return {
				searchPhone: '', 
				nickname:'',
				tableData: [], //表格数据
				pageCount: 0,
				pageNo: 1,
				pageSize: 10,
				state: '1'
			}
		},
		watch:{
		  //  '$route': function(newUrl,oldUrl){
				// if(oldUrl.name=='lietouList'){ //详情页面返回的
				// 	if(oldUrl.params.refresh){
				// 	  this.loadData();
				// 	}
				// }
		  //  }
		},
		async created() {
		   this.loadData();
		},
		methods:{
			// 搜索
			searchData(){
				this.pageNo=1;
				this.loadData();
			},
			//分页
			pageChange(val) {
			  this.pageNo = val;
			  this.loadData()
			},
			async loadData() {
			  const loading = this.$loading({
			    lock: true,
			    text: 'Loading',
			    spinner: 'el-icon-loading',
			    background: 'rgba(0, 0, 0, 0.5)'
			  });
			  try {
			   let data = {
			      "token": this.token,
			      "mobile": this.searchPhone,
			      "companyname": this.nickname,
			      "is_black":1, //是否拉黑 1 非拉黑 -1 拉黑 空或0是全部	1
			      "p": this.pageNo,//分页页码
			      "size": this.pageSize,//分页每页数量
			      "c_status": 0 // 0 全部 1 未审核 2 已审核 -1 已拒绝
			    }
			    let res = await this.$http({
			      url: '/man/Company/getList',
			      method: 'post',
			      params: data
			    });
			    this.tableData = res.data;
			    this.pageCount = res.max_page; //总页数
			    this.pageNo = Number(res.p); //当前页 size当前页
			    loading.close();
			  } catch (e) {
			    console.log(e)
			    loading.close();
			  }
			},
		}
	}
</script>

<style lang="scss" scoped="scoped">
	.el-button.buttonStyle{
	  height: 32px;
	  font-size: 14px;
	  font-family: PingFangSC-Medium, PingFang SC;
	  font-weight: 500;
	  color: #FFFFFF;
	  background:#3674FF;
	  border-radius: 5px;
	  border:0;
	  margin-left:6px;
	  margin-top:2px;
	}
	.answerTable{
		margin-top:15px;
	}
	.lietou-right{
		margin-top:30px;
	}
</style>
